<?php

use Illuminate\Database\Seeder;
use Yangyifan\Administrator\Access\Model\Menus\Menus;
use Yangyifan\Administrator\Access\Model\Roles\Roles;
use Yangyifan\Administrator\Access\Model\RolesRelationMenusModel;

class RolesRelationMenusTableSeeder extends Seeder
{
    /**
     * Run the database seeds.
     *
     * @return void
     */
    public function run()
    {
        echo "Start: " . __CLASS__ . " \r\n";

        $menus = Menus::all();

        // 循环的去遍历添加
        Roles::all()->map(function ($role) use ($menus) {
            $menus->map(function ($menu) use ($role) {
                RolesRelationMenusModel::create([
                    'role_id' => $role->id,
                    'menu_id' => $menu->id,
                ]);
            });
        });

        echo "Finished: " . __CLASS__ . " \r\n";
    }
}
